<?php
/**
* @package controller
* @file indexController.php
* @date 15.09.2009
* @version 1.0
* @copyright sample
* @author Harinath Reddy
* @todo phpDoc comments
*/
require_once 'Zend/Controller/Action.php';

class expressions_IndexController extends Cms_Controller_Action
{
	public function init()
	{
	  $this->view->siteTitle = 'sample';
	  $this->currentPage = 1;
	  $this->resultsPerPage = 8;
			
	}
	public function indexAction()
	{
	  	
			
	}
		
	public function loginAction() 
	{	
	           
		$username=$_POST['Username'];
		$password=md5($_POST['pawd']);
		$log = Doctrine::getTable('Users')->loginCheck($username,$password);
		if($log->numCount>0)
		{
		//store values in session
		$users= Doctrine::getTable('Users')->getUserId($username);
		//echo '<pre>';print_r($Users);exit;
		$_SESSION['start'] = time();
		$_SESSION['expire'] = $_SESSION['start'] + (30* 60) ; //session expires in 15 minutes
		 $_SESSION["sess_userid"]=$users['user_id'];
		 //echo $_SESSION["sess_profilephoto"];exit;
		 $_SESSION["sess_firstname"]=$users['first_name'];
		 $_SESSION["sess_username"]=$users['username'];
		 //echo $_SESSION["sess_username"];exit;
		 $_SESSION["sess_email"]=$users['email'];
		 $userdetails= Doctrine::getTable('UserDetails')->getUserDetails($_SESSION["sess_userid"]);
		 //echo '<pre>';print_r($userdetails);exit;
		  $_SESSION["sess_photo"]=$userdetails['photo'];
		// echo $_SESSION["sess_photo"];exit;        
		 echo "you are successfully lgin into ur account";
		 $this->_redirect("/expressions/index/inbox/1");
		 
		}
		else {
			$this->_redirect("/home/index/index/invalid");
			}
						
	}	
	public function logoutAction()
	{
		if($_SESSION["sess_userid"]!="")
		{
        session_destroy();
		session_unset();
		//$msg = "Logout Successfully";
        $this->_redirect("/home/");
		}
		else
		  $this->_redirect("/home/index/inbox");
			
	}
		public function messageAction()    
	{ 
			
	}
	public function myactivityAction()
	{
	}
	public function viewAction()
	{
		$type=$this->_getParam('id');
		$id=base64_decode($this->_getParam('current_page'));
		
		$memid = $_SESSION["sess_userid"];
		//$memid='sandhyarani.kotaru@gmail.com';
		//echo $type;exit;
		$this->view->type=$type;
		$group_details = Doctrine::getTable('Groups')->getGroupDetails($memid,$currentPage,$resultsPerPage);
		//echo '<pre>';print_r($group_details);exit;
		$this->view->group_details= $group_details;
		$this->view->count= count($group_details['result']);
		if($type==1)
		{
		
		$result = Doctrine::getTable('Expressions')->getExpressions($memid,1,8);
		//echo '<pre>';print_r($result);exit;	
		//echo $result['result'][0]['UserDetails']['photo'];exit;
		$r = Doctrine::getTable('Expressions')->getDetails($id);
		//echo '<pre>';print_r($r);exit;
		$this->view->details = $r;		
		}
		else if($type == 2||$type==3)
		{
			if($type == 2)
			$send_type = 1;
			else $send_type = 0;
			//echo $send_type;exit;
			$result = Doctrine::getTable('Expressions')->sentMails($memid,$send_type,1,8);
			//echo '<pre>';print_r($result);exit;
			$r = Doctrine::getTable('Expressions')->getSentDetails($id,$send_type);
			//echo '<pre>';print_r($r);exit;
			//echo '<pre>';print_r($r['ExpressionsSent'][0]['Users'][0]['first_name']);exit;
			$this->view->details = $r;
		}
		else if($type == 4)
		{
			$result = Doctrine::getTable('Expressions')->trashMails($memid,1,8);
			$r = Doctrine::getTable('Expressions')->getTrashDetails($id);
			//echo '<pre>';print_r($r);exit;
			$this->view->details = $r;
		}
		else if($type == 5)
		{
			$result = Doctrine::getTable('Expressions')->getAnonymousMails($memid,1,8);
			$r = Doctrine::getTable('Expressions')->getAnonymousDetails($id);
			//echo '<pre>';print_r($r);exit;
			$this->view->details = $r;
		}
		else if($type == 6)
		{
			$result = Doctrine::getTable('Expressions')->getBlockedExpressions($memid,1,8);
			$r = Doctrine::getTable('Expressions')->getBlockedDetails($id);
			//echo '<pre>';print_r($r);exit;
			$this->view->details = $r;
		}
		$this->view->getExpressions = $result;
		$this->view->type = $type;
		
		$attachments = Doctrine::getTable('ExpressionsAttachements')->getAttachments($id);
		//echo '<pre>';print_r($atachments);exit;
		
		$this->view->total=count($attachments);
		$this->view->attachments = $attachments;
				
	}
	
	
	public function uploadImagesAction()
	  {
	   //echo "uploading";exit;
		  $this->_helper->layout->disableLayout();
		  $this->getHelper('viewRenderer')->setNoRender();
		  $imagesDir = '../'.$this->CONFIG->path->photosThumb;
		if(isset($_FILES['vfile']))
		  {
			 $size=$_FILES['vfile']['size'];
			 //echo $_FILES['vfile']['name'];exit;
		   	 $name = time().'_-_'.$_FILES['vfile']['name'];
			//echo $name;exit;
		 if($size>209715200)
			 {
				echo "error file size > 200 MB";
				unlink($_FILES['vfile']['tmp_name']);
				exit;
			}
			echo $vidfile = $this->uploadFile($_FILES['vfile']['tmp_name'],$imagesDir,$name);
		}
	}
		public function uploadFile($tnm,$path,$fnm)
	 {
	 //echo "hi from  upload file method";
		   $fnm = str_replace(' ','_',$fnm);
		  if(move_uploaded_file($tnm,$path.$fnm))
		    {
			   //createFixedthumb($path.$fnm, $path.$fnm, "450", "450");
			   return $fnm;
		    }
		 else
			return "";
     }
	 
	 

	public function paginationAction()
	{
		//echo "pagination page";exit;
		$type = $this->_getParam('id') == 0? 1:$this->_getParam('id');
		//echo $type;exit;
		$currentPage = $this->_getParam('current_page') == 0? 1:$this->_getParam('current_page');
		$resultsPerPage = $this->_getParam('results_per_page') == 0? 8:$this->_getParam('results_per_page');
		//echo $currentpage,$resultsPerPage;exit;
		$memid=$_SESSION["sess_userid"];
		$this->view->type= $type;
		$this->view->params ="";
		//$ideaDetails = Doctrine::getTable('Expressions')->getExpressions($_SESSION["sess_memberid"],$currentPage, $resultsPerPage);
		if($type == 1)
		{
			$ideaDetails = Doctrine::getTable('Expressions')->getExpressions($memid,$currentPage, $resultsPerPage);
		} 
		else if($type == 2 || $type==3)
		{
					if($type == 2)
					$send_type = 1;
					else $send_type = 0;
					$ideaDetails = Doctrine::getTable('Expressions')->sentMails($memid,$send_type,$currentPage, $resultsPerPage);
		}
		else if($type == 4)
		{
		$ideaDetails = Doctrine::getTable('Expressions')->trashMails($memid,$currentPage, $resultsPerPage);
		}
		else if($type == 5)
		{
			$ideaDetails = Doctrine::getTable('Expressions')->getAnonymousMails($memid,$currentPage, $resultsPerPage);
		}
		else if($type == 6)
		{
			$ideaDetails = Doctrine::getTable('Expressions')->getBlockedExpressions($memid,$currentPage, $resultsPerPage);
		}
		else if($type == 7)
		{
			$ideaDetails = Doctrine::getTable('Expressions')->getGroupDetailsByid($memid,$currentPage, $resultsPerPage);
		}
		//echo '<pre>';print_r($ideaDetails);exit;
		$this->view->getExpressions = $ideaDetails;
		//echo '<pre>';print_r($ideaDetails);exit;
		$jsonData['output'] = $this->view->render('index/message.html');
		$jsonData['pages'] = $ideaDetails['pages'];
	    $jsonData['pager'] = $ideaDetails['pager'];
	    $jsonData['currentPage'] = $ideaDetails['currentPage'];
		$jsonData['resultsCount'] = $ideaDetails['resultsCount'];
		$this->_helper->json->sendJson($jsonData);
	}
	public function inboxAction() 
	{	
		$this->view->type= $this->_getParam('id');
		$result_type = $this->_getParam('current_page');
		//echo '<pre>';print_r($_POST);exit;
		if($_SESSION["sess_userid"]!="")
		{
			$this->view->inboxactive="active";
			$this->view->sentactive="";
			$this->view->draftactive="";
			$this->view->trashactive="";	
			$this->view->params ="";
			$memid = $_SESSION["sess_userid"];
			//$memid='sandhyarani.kotaru@gmail.com';
			$result = Doctrine::getTable('Expressions')->getExpressions($memid,$this->currentPage,$this->resultsPerPage);
			//echo '<pre>';print_r($result);exit;	
			//echo $result['result'][0]['UserDetails']['photo'];exit;		
			$this->view->getExpressions = $result;
			$groups = Doctrine::getTable('groups')->getGroupDetailsByid($memid);
			//echo '<pre>';print_r(count($groups));exit;
			$this->view->groups= $groups;
			$this->view->count= count($groups);
			$this->view->groups=$groups;
			echo $analysis = $this->analysis();			
		}
		else 
		{
			$this->_redirect("/home/");
		}
     }
		public function composeAction() 
		{
			if($_SESSION["sess_userid"]!="")
		{
			   	$memid=$_SESSION["sess_userid"];
				$a = Doctrine::getTable('Expressions')->getMails($memid);
				//echo '<pre>';print_r($a);exit;
				$jsonData = array();
				if(count($a)>0)
				{
					foreach($a as $key=>$mails)
					{
						$jsonData[$key]['key'] = $mails['email'];
						$jsonData[$key]['value'] = $mails['email'];					
					}
				}
				$this->_helper->json->sendJson($jsonData);
		}	
	}
	 public function preview1Action()
	{
	    $this->_helper->layout->disableLayout();
	    $colorid = $this->_getParam('id');
		//echo $colorid;exit;
		$result = Doctrine::getTable('MessageIntensity')->getColorsById($colorid);
		$this->view->result=$result;
	}

	public function saveAction()    
	{ 
	
		
		echo '<pre>';print_r($_POST);print_r($_FILES);exit;
		$data = $_POST;
		if( $data['checkbox']!="")
		{
			//echo "check box selected";exit;
		$anonymous=1;
		}
		else{
		$anonymous=0;
		}
		$memid=$_SESSION["sess_userid"];
		$result = Doctrine::getTable('Expressions')->addExpressions($data,$anonymous);
		foreach($data['select3'] as $email)
		{
			$receiver_id = Doctrine::getTable('Users')->getUserIdByEmail($email);
			//echo $receiver_id['user_id'];exit;
			$is_group=0;
			$r = Doctrine::getTable('ExpressionsSent')->addExpressions($email,$result,$receiver_id['user_id'],$is_group,$memid);
		}
		if($data['group'])
		{
			$is_group=1;
			$r = Doctrine::getTable('ExpressionsSent')->addGroupExpressions($result,$data['group'],$is_group,$memid);
			//echo $r;exit;
		}
		//echo '<pre>';print_r($result);exit;
		if($result)
		{
		  //echo $result;
		  $count=count($data['fileNames']);
		  //exit;
		  $i=0;
			while($i<$count)
			{
					$filename=$data['fileNames'][$i];
					//exit;
					$r = Doctrine::getTable('ExpressionsAttachements')->addAttachements($filename,$result);
					$i++;
			}
          $this->_redirect("/expressions/index/sent/2");
		}
		else
		{
		$this->_redirect("/Expressions/messages/compose/fail");
		}	
	}
	public function analysis() 
	{	
		// analysis action#######################################################
		//$mailid = $_SESSION["sess_email"];
		$type = 1;
		$memid=$_SESSION["sess_userid"];
                $r = Doctrine::getTable('Expressions')->getExpressions($memid,$currentPage, $resultsPerPage);
				//echo '<pre>';print_r($r['resultsCount']);exit;
				$this->view->receivedMails = $r['resultsCount'];
				$rl = Doctrine::getTable('Expressions')->SentMails($memid,$currentPage,$type ,$resultsPerPage);
				//echo '<pre>';print_r($r1['resultsCount']);exit;
				$this->view->sentMails = $rl[resultsCount];	
				$chsent = '';
               $totcolors = Doctrine::getTable('MessageIntensity')->getTotalColors();
			   $count = $totcolors[numCount];
			   $colors = Doctrine::getTable('MessageIntensity')->getColors();
			   //echo count($colors);exit;
			   //echo $colors['1']["message_intensity"];exit;
			   //echo count($colors)
			   //$my_colors=mysql_fetch_array($colors['id']);
			   $i = 0;
			   //echo $colors[$i]['id'];exit;
			   //start of the sent graph
			   while($colors[$i]["id"]!=$count)
				{
				    $ch = Doctrine::getTable('Expressions')->getSentColors($memid,$colors[$i]["id"]);
					$ch1 = $ch->numCount;
					//echo $ch1;exit;
					if($ch1!=0)
					{
						$nr=$ch1;
						if($i!=$count)
						{
							$chsent.=$nr.",";
							$chcolorCode.=$colors[$i]['message_intensity'].",";
							$chcolorType.=$colors[$i]['desc']."|";
							$chcolorcounts.=$nr."|";
							//echo $chsent." ".$chcolorCode." ".$chcolorType." ".$chcolorcounts;exit;
						}
						else
						{
							$chsent.=$nr;
						}
					}
					$i++;
					//echo $i;exit;
				}
				if($chsent!='')
				{
						$chsent = trim($chsent,',');
						$chcolorCode = trim($chcolorCode,',');
						$chcolorType = trim($chcolorType,'|');
						$chcolorcounts = trim($chcolorcounts,'|');
				}
				if($chsent != '')
				{
	
					/////Dashboard Settings
						if($rl['resultsCount'] == 0)
						{
							$sent_cht = "Disabled";
							$this->view->sent_cht = $sent_cht;
						}
						else {
								$this->view->sent_cht="<img src='http://chart.apis.google.com/chart?cht=p&chs=300x150&chd=t:".$chsent."&chco=".$chcolorCode."&chl=".$chcolorType."&chdl=".$chcolorcounts."' >";
							  }
					///End
				}
				else 
				{
					$this->view->sent_cht = '&nbsp;&nbsp;&nbsp;No data available';
				}
				// end of the sent graph
				//start of received graph
				$chrec = '';
				$i = 0;
				//echo $chrec;exit;
				while($colors[$i]["id"]!=$count)
				{
				    $ch = Doctrine::getTable('Expressions')->getReceivedColors($memid,$colors[$i]["id"]);
					$ch1 = $ch->numCount;
					//echo $ch1;exit;
					if($ch1!=0)
					{
						$nr=$ch1;
						if($i!=$count)
						{
							$chrec.=$nr.",";
							$chcolorCoderec.=$colors[$i]['message_intensity'].",";
							$chcolorTyperec.=$colors[$i]['desc']."|";
							$chcolorcountsrec.=$nr."|";
							//echo $chrec." ".$chcolorCoderec." ".$chcolorTyperec." ".$chcolorcountsrec;exit;
						}
						else
						{
							$chrec.=$nr;
						}
					}
					$i++;
				}
				if($chrec != '')
				{
						$chrec = trim($chrec,',');
						$chcolorCoderec = trim($chcolorCoderec,',');
						$chcolorTyperec = trim($chcolorTyperec,'|');
						$chcolorcountsrec = trim($chcolorcountsrec,'|');
				}
				if($chrec != '')
				{
	
					/////Dashboard Settings
						if($r['resultsCount'] == 0)
						{
							$rec_cht = "Disabled";
							$this->view->rec_cht = $rec_cht;
						}
						else 
						{
							$this->view->rec_cht="<img src='http://chart.apis.google.com/chart?cht=p&chs=300x150&chd=t:".$chrec."&chco=".$chcolorCoderec."&chl=".$chcolorTyperec."&chdl=".$chcolorcountsrec."' >";
						}
					///End
				}
				else 
				{
					$this->view->rec_cht = '&nbsp;&nbsp;&nbsp;No data available';
				}
				//end of the received graph
		//end of analysis###########################################
     
	 }

	public function sentAction()    
	{ 
		$this->view->type= $this->_getParam('id');
		if($_SESSION["sess_userid"]!="")
		{
		$this->view->sentactive="active";
		$this->view->inboxactive="";
		$this->view->draftactive="";
		$this->view->trashactive="";
		
		$this->view->message = $message;
		$this->view->params ="";
		//$memid = $_SESSION["sess_memberid"];
		$memid=	$_SESSION["sess_userid"];
		$send_type= 1;
		$result = Doctrine::getTable('Expressions')->sentMails($memid,$send_type,1,8);
		//echo '<pre>';print_r($result);exit;	
		//echo $result['result'][0]['UserDetails']['photo'];exit;		
		$this->view->getExpressions = $result;
		$groups = Doctrine::getTable('groups')->getGroupDetailsByid($memid);
			//echo '<pre>';print_r(count($groups));exit;
			$this->view->groups= $groups;
			$this->view->count= count($groups);
			$this->view->groups=$groups;
		echo $analysis = $this->analysis();
		$this->render('inbox');
		}
		else 
		{
		$this->_redirect("/home");
		}
			
	}
	 
	 public function draftsAction()
	 {
		$this->view->type= $this->_getParam('id');
		if($_SESSION["sess_userid"]!="")
		{
		$this->view->sentactive="";
		$this->view->inboxactive="";
		$this->view->draftactive="active";
		$this->view->trashactive="";

		$this->view->params ="";
		//$memid = $_SESSION["sess_memberid"];
		$memid=$_SESSION["sess_userid"];
		$send_type= 0;
		$result = Doctrine::getTable('Expressions')->sentMails($memid,$send_type,1,8);
		//echo '<pre>';print_r($result);exit;	
		//echo $result['result'][0]['UserDetails']['photo'];exit;		
		$this->view->getExpressions = $result;
		$groups = Doctrine::getTable('groups')->getGroupDetailsByid($memid);
			//echo '<pre>';print_r(count($groups));exit;
		$this->view->groups= $groups;
		$this->view->count= count($groups);
		$this->view->groups=$groups;
		echo $analysis = $this->analysis();     
		$this->render('inbox');
    	}
		else 
		{
			$this->_redirect("/home/index/index/logout");
		}
	}
		public function trashAction()
	 {
		$this->view->type= $this->_getParam('id');
		if($_SESSION["sess_userid"]!="")
		{
		    $this->view->sentactive="";
			$this->view->inboxactive="";
		   $this->view->draftactive="";
		   $this->view->trashactive="active";
	
		$this->view->message = $message;
		$this->view->params ="";
			//$memid = $_SESSION["sess_memberid"];
			$memid=$_SESSION["sess_userid"];
			$result = Doctrine::getTable('Expressions')->trashMails($memid,1,8);
		//echo '<pre>';print_r($result);exit;	
		//echo $result['result'][0]['UserDetails']['photo'];exit;		
		$this->view->getExpressions = $result;
		$groups = Doctrine::getTable('groups')->getGroupDetailsByid($memid);
			//echo '<pre>';print_r(count($groups));exit;
		$this->view->groups= $groups;
		$this->view->count= count($groups);
		$this->view->groups=$groups;
		echo $analysis = $this->analysis();
		$this->render('inbox');
    	}
		else 
		{
			$this->_redirect("/home/index/index/logout");
		}
	}
	public function anonymousAction()
	{
		$this->view->type= 5;
		$this->view->params ="";
		$memid = $_SESSION["sess_userid"];
		//echo $memid;exit;
		$result = Doctrine::getTable('Expressions')->getAnonymousMails($memid,1,8);
		$this->view->getExpressions = $result;
	  	//echo '<pre>';print_r($result);exit;
		echo $analysis = $this->analysis();
			
	}
	public function blockAction()
	{
		$this->view->type= 6;
		$this->view->params ="";
		$userid = $_SESSION["sess_userid"];
		//echo $memid;exit;
		$result = Doctrine::getTable('Expressions')->getBlockedExpressions($userid,1,2);
		$this->view->getExpressions = $result;
	  	//echo '<pre>';print_r($result);exit;
		echo $analysis = $this->analysis();
			
	}
	public function closeAction()
	{
			$type= $this->_getParam('id');
			//echo $type;exit;
			$this->view->type=$type;
			$result_type = $this->_getParam('current_page');
			//echo $result_type;exit;
			 if($result_type == "close")
				{
					$id = base64_decode($this->_getParam('results_per_page'));
					//echo $id;exit;
					if($type == 1)
					{
					$status="RDelete";
					$r2 = Doctrine::getTable('ExpressionsSent')->deleteExpression($_SESSION['sess_userid'],$status,$id);
					$this->_redirect("/expressions/index/inbox/1");
					}
					else if($type == 2 || $type == 3)
					{
					$status="SDelete";
					//echo $status;exit;
					$r2 = Doctrine::getTable('ExpressionsSent')->deleteSentExpression($_SESSION['sess_userid'],$status,$id);
					if($type==2)
					$this->_redirect("/expressions/index/sent/".$type);
					else $this->_redirect("/expressions/index/drafts/".$type);
					}
					else if($type == 4)
					{
					$status="Delete";
					$r2 = Doctrine::getTable('ExpressionsSent')->deleteExpression($_SESSION['sess_userid'],$status,$id);
					$this->_redirect("/expressions/index/trash/4");
					} else {
					
					}
			}
		}
		function changeStatusAction()
		{
					//echo '<pre>';print_r($_POST);exit;

					$id = $_POST['val'];
					$action = $_POST['tpye'];
					$type = $_POST['msgType'];
					
					if($action == 'close')
					{
						if($type == 1)
						{
						//echo 'sdfsdf';exit;
						$status="RDelete";
						$r2 = Doctrine::getTable('ExpressionsSent')->deleteExpression($_SESSION['sess_userid'],$status,$id);
						}
						else if($type == 2 || $type == 3)
						{
						$status="SDelete";
						//echo $status;exit;
						$r2 = Doctrine::getTable('ExpressionsSent')->deleteSentExpression($_SESSION['sess_userid'],$status,$id);
						
						//if($type==2)
						//$this->_redirect("/expressions/index/sent/".$type);
						//else $this->_redirect("/expressions/index/drafts/".$type);
						}
						else if($type == 4)
						{
						$status="Delete";
						$r2 = Doctrine::getTable('ExpressionsSent')->deleteExpression($_SESSION['sess_userid'],$status,$id);
						$this->_redirect("/expressions/index/trash/4");
						}
						else if($type == 5)
						{
						$status="Delete";
						$r2 = Doctrine::getTable('ExpressionsSent')->deleteExpression($_SESSION['sess_userid'],$status,$id);
						$this->_redirect("/expressions/index/trash/4");
						}
						else if($type == 6)
						{
						$status="Delete";
						$r2 = Doctrine::getTable('ExpressionsSent')->deleteExpression($_SESSION['sess_userid'],$status,$id);
						$this->_redirect("/expressions/index/trash/4");
						}
					
					} else if($action == 'block'){
					
						$r1 = Doctrine::getTable('Memberstatus')->blockUser($_SESSION['sess_userid'],$id);
						$r2 = Doctrine::getTable('ExpressionsSent')->setstatusInactive($_SESSION['sess_userid'],$id);
						//$this->_redirect("/expressions/index/inbox/1/success");	
					}

					$jsonData['output'] = $r2;
					$this->_helper->json->sendJson($jsonData);
					//$this->paginationAction();

						
		}
	public function addtogroupAction()
	{
		//echo $_POST;exit;
		$id = $_POST['val'];
		$action = $_POST['tpye'];
		$type = $_POST['msgType'];
		$result = Doctrine::getTable('GroupDetails')->getGroupDetailsByid($id,$type);
		//echo $result;exit;
		$user_email = Doctrine::getTable('Users')->getEmail($type);
		$r2 = Doctrine::getTable('GroupDetails')->addDetailsToGroup($id,$type,$user_email);
		$jsonData['output'] = $r2;
		$this->_helper->json->sendJson($jsonData);
	
	}
	public function changegroupStatusAction()
	{
		//echo $_POST;exit;
		$status = $_POST['val'];
		$group_id = $_POST['type'];
		//echo $status."  ".$group_id;exit;
		if($group_id!=0)
		{
			$memid = $_SESSION["sess_userid"];
			$result = Doctrine::getTable('Groups')->changeStatusGroupId($memid,$status,$group_id);
				//echo $result;exit;
			$jsonData['output'] = $result;
			$this->_helper->json->sendJson($jsonData);
		}
		else
		{
		$memid = $_SESSION["sess_userid"];
		$result = Doctrine::getTable('Groups')->changeStatusGroup($memid,$status);
		//echo $result;exit;
		$jsonData['output'] = $result;
		$this->_helper->json->sendJson($jsonData);
		}
	
	}
	public function addgroupAction()
	{
		$name = $_POST['val'];
		$desc = $_POST['tpye'];
		//echo $name,$desc;exit;
		$memid = $_SESSION["sess_userid"];
		$result = Doctrine::getTable('Groups')->getGroupName($memid,$name);
		//echo $result[numCount]);exit;
		if($result[numCount]==0)
		{
		//echo "chandra";exit;
		$r2 = Doctrine::getTable('Groups')->addGroup($memid,$name,$desc);
		//echo $r2;exit;
		$jsonData['output'] = $r2;
		$this->_helper->json->sendJson($jsonData);
		}
		else
		{
			$jsonData['output'] = 0;
			$this->_helper->json->sendJson($jsonData);
		}
			
		
	}
	public function removeAction()
	{
		$this->_helper->layout->disableLayout();
		//$videosTemp= '../'.$this->CONFIG->path->contentTempFiles;
		 $videosTemp = '../'.$this->CONFIG->path->photosThumb;
		$videoFile = trim($_GET['filename']);
		@unlink($videosTemp.$videoFile);
		$jsonData['rows']  = $rows;
		$this->_helper->json->sendJson($jsonData);

	}	
	public function groupsAction()
	{
		//echo $_POST;exit;
		$this->view->type= 7;
		$memid = $_SESSION["sess_userid"];
		//echo $memid;exit;
		$result = Doctrine::getTable('Groups')->getGroupDetails($memid,$currentPage,$resultPerPage);
		//echo '<pre>';print_r($result);exit;
		$count=count($result['result']);
		$this->view->total=$count;
		$this->view->result=$result;
		echo $analysis = $this->analysis();
			
	}	
	public function groupviewAction()
	{
		$group_id=base64_decode($this->_getParam('id'));
		$memid = $_SESSION["sess_userid"];
		//echo $memid;exit;
		$result = Doctrine::getTable('GroupDetails')->getGroupDetailsByid($memid,$group_id);
		//echo '<pre>';print_r($result);exit;
		$count=count($result);
		$this->view->count=$count;
		$this->view->result=$result;
		echo $analysis = $this->analysis();
			
	}	
	public function removeRecordAction()
	{
		$id = $_POST['val'];
		$memid = $_SESSION["sess_userid"];
		//echo $memid,$id;exit;
		$result = Doctrine::getTable('GroupDetails')->removeRecord($memid,$id);
		//echo '<pre>';print_r($result);exit;
		$jsonData['output'] = 1;
		$this->_helper->json->sendJson($jsonData);
		echo $analysis = $this->analysis();
			
	}	

}	
